#ifndef MSGSOCKET_H
#define MSGSOCKET_H

#include <QObject>
#include <QTcpSocket>
#include <QFile>
#include <QApplication>

class MsgSocket : public QObject
{
    Q_OBJECT
public:
    explicit MsgSocket(QObject *parent = 0, QTcpSocket *tcpSocket = NULL);
    ~MsgSocket();

    int GetUserId() const;
    void Close();
signals:
    void signalConnected();
    void signalDisConnected();
    void signalDownloadFile(const QJsonValue &json);
    void signalMsgToClient(const quint8 &type, const int &id, const QJsonValue &dataVal);
public slots:

private:
    QTcpSocket *m_tcpSocket;
    int         m_nId;

public slots:
    // 消息回发
    void SltSendMessage(const quint8 &type, const QJsonValue &json);

private slots:
    void SltConnected();
    void SltDisconnected();
    void SltReadyRead();

private:
    // 消息解析和抓转发处理
    void ParseLogin(const QJsonValue &dataVal);
    void ParseUserOnline(const QJsonValue &dataVal);
    void ParseLogout(const QJsonValue &dataVal);
    void ParseUpdateUserHead(const QJsonValue &dataVal);

    void ParseReister(const QJsonValue &dataVal);
    void ParseAddFriend(const QJsonValue &dataVal);
    void ParseAddGroup(const QJsonValue &dataVal);
    void ParseCreateGroup(const QJsonValue &dataVal);

    void ParseGetMyFriend(const QJsonValue &dataVal);
    void ParseGetMyGroups(const QJsonValue &dataVal);

    void ParseRefreshFriend(const QJsonValue &dataVal);
    void ParseRefreshGroups(const QJsonValue &dataVal);

    void ParseFriendMessages(const QByteArray &reply);
    void ParseGroupMessages(const QByteArray &reply);
};

#endif // MSGSOCKET_H
